package com.futer.ssm.service.impl;

import com.futer.ssm.dao.*;
import com.futer.ssm.model.*;
import com.futer.ssm.service.Service;

import javax.annotation.Resource;
import java.util.List;

@org.springframework.stereotype.Service
public class ServiceImpl implements Service {

    @Resource
    CollectMapper collectMapper;
    @Resource
    BorrowMapper borrowMapper;
    @Resource
    ShoppingCatMapper shoppingCatMapper;
    @Resource
    SettingMapper settingMapper;
    @Resource
    AllAppMapper allAppMapper;
    @Resource
    UserMapper userMapper;
    @Resource
    IdentifyingCodeMapper identifyingCodeMapper;



    /**
     * 实现收藏接口
     * @param collect
     * @return
     */
    @Override
    public int collect(Collect collect) {
        return collectMapper.insertSelective(collect);
    }

    @Override
    public List<Collect> getCollect(CollectExample c) {
        return collectMapper.selectByExample(c);
    }

    @Override
    public int removeCollect(CollectExample collectExample) {
        return collectMapper.deleteByExample(collectExample);
    }


    /**
     * 实现借阅入口
     */
    //借阅，插入表格
    @Override
    public int borrowObject(Borrow borrow) {
        return borrowMapper.insertSelective(borrow);
    }

    //获取所有表格
    @Override
    public List<Borrow> getAllBorrow(BorrowExample borrowExample) {
        return borrowMapper.selectByExample(borrowExample);
    }



    /**
     * 购物车入口
     */
    @Override
    public int addShoppingCat(ShoppingCat shoppingCat) {
        return shoppingCatMapper.insertSelective(shoppingCat);
    }

    @Override
    public List<ShoppingCat> getAllShoppingCat(ShoppingCatExample shoppingCatExample) {
        return shoppingCatMapper.selectByExample(shoppingCatExample);
    }

    @Override
    public int removeShoppingCat(ShoppingCatExample shoppingCat) {
        return shoppingCatMapper.deleteByExample(shoppingCat);
    }


    /**
     * 框架设置入口
     */
    public List<Setting> getSetting(SettingExample settingExample){
        return settingMapper.selectByExample(settingExample);
    }

    public int updateSetting(Setting setting){
        return settingMapper.updateByPrimaryKey(setting);
    }


    /**
     * 应用设置入口
     */
    @Override
    public List<AllApp> getAllApp(AllAppExample allAppExample) {
        return allAppMapper.selectByExample(allAppExample);
    }

    @Override
    public int deleteApp(AllAppExample allApp) {
        return allAppMapper.deleteByExample(allApp);
    }

    @Override
    public int addApplication(AllApp allApp){
        return this.allAppMapper.insertSelective(allApp);
    }

    @Override
    public int updateApp(AllApp allAppExample) {
        return this.allAppMapper.updateByPrimaryKeySelective(allAppExample);
    }


    /**
     * 用户管理
     * @param userExample
     * @return
     */
    @Override
    public List<User> getUser(UserExample userExample) {
        return userMapper.selectByExample(userExample);
    }

    @Override
    public int addUser(User user) {
        return userMapper.insertSelective(user);
    }

    @Override
    public int deleteUser(UserExample user) {
        return userMapper.deleteByExample(user);
    }

    @Override
    public int updateUser(User user) {
        return userMapper.updateByPrimaryKeySelective(user);
    }

    //获取验证码进行校验
    @Override
    public IdentifyingCode getCode(String email) {
        return identifyingCodeMapper.selectByPrimaryKey(email);
    }

    //向数据库插入验证码
    @Override
    public int addCode(IdentifyingCode identifyingCode) {
        return identifyingCodeMapper.insert(identifyingCode);
    }

    //删除验证码
    @Override
    public int deleteCode(String email) {
        return identifyingCodeMapper.deleteByPrimaryKey(email);
    }


}
